4页:文字域事件
作者:Thau!
文字域可以链接onBluronFocus、和onChange事件。当有
人点击文字域的里边时则发生
onFocus事件。而如果点击文
字域的外面或按了
tab键时则发生onblur事件。如果有人改
变了文字域内的内容然后转到文字域外部的区域时则发生
onChange事件。

试着做这些事情看下面的文字域会发生什么情况。

以下是编制方法:文字域的编码:



<input type="text" name="first_text" 

	onFocus="writeIt('focus');" 

	onBlur="writeIt('blur');" 

	onChange="writeIt('change');">

每一个事件处理器调用函数writeIt(),该函数在
首部中已作了定义。首部中的编码如下:

<head>

<title>Text Field Events</title>

<script language="JavaScript">

<!-- hide me

function writeIt(the_word)

{

	var word_with_return = the_word + "\n";

	window.document.first_form.the_textarea.value += 

		word_with_return;

}

// show me -->

</script>

</head>
前几行是典型的JavaScript预定义。主体中的第1

var word_with_return = the_word + "\n";
将一个变量word_with_return进行初始化为函数处
理后的字符串并加上换行符
"\n".。注意"\n" 是标
准的计算机指令。

下一行


window.document.first_form.the_textarea.value += word_with_return;
将文字区域的值设置为其原值加新变量。其作用相
当于

window.document.first_form.the_textarea.value = 

window.document.first_form.the_textarea.value + word_with_return;
目前我们已经学习了文字域和文字区域(值)的属性,接下
来我们学习文字域和文字区域处理所用的方法:
blur()
focus()、和select()

下面的链接显示了focus() ()如何工作。注意他们工作一
次后可能会终止功能。

错误!超级链接引用无效。 错误!超级链接引用无效。

<form name="method_form">

<input type="text" name="method_text" size=40 value=
"Hey, hey, we're the monkeys">

</form>



<a href="#" onMouseOver=
"window.document.method_form.method_text.focus();">
Mouseover to focus</a>

<a href="#" onMouseOver=
"window.document.method_form.method_text.select();">
Mouseover to select</a>
其使用方法和调用任何对象方法的做法是一样的:
object_name.method(). 该文字域的名称是
window.document.form_name.text_field_name
所以用下列语句就可调用文字域的
focus()方法。

window.document.method_form.method_text.focus();

1页:5日课程介绍
2页:介绍反馈表单
3页:控制文字域的值
4页:文字域事件
5页:反馈表单处理器
6页:文字域的练习
7页:复选框
8页:单选框
9页:选单
10页:在选单中应用onchange命令



以下为表单和链接的编码: